﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Xml;
using umbraco;

namespace Nibble.Umb.Locator
{
    public class Utility
    {
        /// <summary>
        /// Gets the google maps key.
        /// </summary>
        /// <returns></returns>
        public static string GetGoogleMapsKey()
        {
            
            try
            {
                XmlDocument config = new XmlDocument();
                config.Load(HttpContext.Current.Server.MapPath("/config/Nibble.Umb.Locator.config"));

                XmlNode key = config.SelectSingleNode(string.Format("/config/key [contains(@url,'{0}')]", HttpContext.Current.Request.Url.Host));

                return key.Attributes["value"].Value;
            }
            catch
            {

                throw new Exception("Google maps Key not found for domain " + HttpContext.Current.Request.Url.Host);
            }

        }

        /// <summary>
        /// Gets the number format info.
        /// </summary>
        /// <returns></returns>
        public static System.Globalization.NumberFormatInfo NumberFormatInfo
        {
            get
            {
                System.Globalization.NumberFormatInfo info = new System.Globalization.NumberFormatInfo();
                info.NumberDecimalSeparator = ".";
                info.NumberGroupSeparator = ",";
                return info;
            }
        }

        public static bool UseLegacySchema
        {
            get
            {
               
                return UmbracoSettings.UseLegacyXmlSchema;
             
            }
        }

       
    }
    
}
